﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using EBEInventory_DAL;

public partial class Inventory_Items_Management_ItemInfo22 : System.Web.UI.Page
{
    InventoryEntities ctx = null;
    string parCatID;

    protected void Page_Load(object sender, EventArgs e)
    {
        if (!IsPostBack)
        {

            string opType = Server.UrlDecode(Request.QueryString["Operation"]);
ViewState["Operation"] = btn_RegItem.Text = opType;
parCatID = Server.UrlDecode(Request.QueryString["ParentID"]);

            if (string.Compare(opType, "Register") == 0)
            {
                
                ViewState["ParentCatID"] = parCatID;
            }

            
            if (parCatID != null)
                txt_ItemCode.Text = parCatID;
            txt_ItemCode.Enabled = false;

        }

        else
        {
            ctx = InitConnection.Initialize();
        }
    }
    protected void btn_RegItem_Click(object sender, EventArgs e)
    {
        if (string.Compare(ViewState["Operation"].ToString(), "Register") == 0)
        {
            Dictionary<string, string> item = new Dictionary<string, string>();
            item["ItemID"] = txt_ItemID.Text;
            item["Name"] = txt_ItemName.Text;
            item["ItemCode"] = txt_ItemCode.Text;
            item["Unit"] = txt_ItemUnit.Text;
            item["Serial"] = txt_ItemSerialNo.Text;
            item["Model"] = txt_ItemModel.Text;
            item["PartNo"] = txt_ItemPartNo.Text;
            item["HasAddInfo"] = true.ToString();
        
            ItemsOps.AddItem(item, ctx);
        }

        Response.Redirect("~/Inventory/Items Management//ListItems.aspx");

    }
}